package com.xjy.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.xjy.common.exception.UtilException;
import com.xjy.system.domain.vo.SysTransactionUnitVo;
import lombok.RequiredArgsConstructor;

import javax.validation.constraints.*;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.domain.vo.SysBudgetMngVo;
import com.xjy.system.domain.bo.SysBudgetMngQueryBo;
import com.xjy.system.domain.bo.SysBudgetMngAddBo;
import com.xjy.system.domain.bo.SysBudgetMngEditBo;
import com.xjy.system.service.ISysBudgetMngService;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 预算管理Controller
 *
 * @author zc
 * @date 2022-02-12
 */
@Api(value = "预算管理控制器", tags = {"预算管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/SysBudgetMng")
public class SysBudgetMngController extends BaseController {

	private final ISysBudgetMngService iSysBudgetMngService;

	/**
	 * 查询预算管理列表
	 */
	@ApiOperation("查询预算管理列表")
	@PreAuthorize("@ss.hasPermi('system:SysBudgetMng:list')")
	@GetMapping("/list")
	public TableDataInfo<SysBudgetMngVo> list(@Validated SysBudgetMngQueryBo bo) {
		this.startPage();
		return iSysBudgetMngService.queryPageList(bo);
	}

	/**
	 * 导出预算管理列表
	 */
	@ApiOperation("导出预算管理列表")
	@PreAuthorize("@ss.hasPermi('system:SysBudgetMng:export')")
	@Log(title = "预算管理", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<SysBudgetMngVo> export(@Validated SysBudgetMngQueryBo bo) {
		List<SysBudgetMngVo> list = iSysBudgetMngService.queryList(bo);
		ExcelUtil<SysBudgetMngVo> util = new ExcelUtil<SysBudgetMngVo>(SysBudgetMngVo.class);
		return util.exportExcel(list, "预算管理");
	}

	/**
	 * 获取预算管理详细信息
	 */
	@ApiOperation("获取预算管理详细信息")
	@PreAuthorize("@ss.hasPermi('system:SysBudgetMng:query')")
	@GetMapping("/{id}")
	public AjaxResult<SysBudgetMngVo> getInfo(@NotNull(message = "主键不能为空")
											  @PathVariable("id") Long id) {
		return AjaxResult.success(iSysBudgetMngService.queryById(id));
	}

	/**
	 * 新增预算管理
	 */
	@ApiOperation("新增预算管理")
	@PreAuthorize("@ss.hasPermi('system:SysBudgetMng:add')")
	@Log(title = "预算管理", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody SysBudgetMngAddBo bo) {
		return toAjax(iSysBudgetMngService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改预算管理
	 */
	@ApiOperation("修改预算管理")
	@PreAuthorize("@ss.hasPermi('system:SysBudgetMng:edit')")
	@Log(title = "预算管理", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/edit")
	public AjaxResult<Void> edit(@Validated @RequestBody SysBudgetMngEditBo bo) {
		SysBudgetMngVo sysBudgetMngVo = iSysBudgetMngService.queryById(bo.getId());
		if (sysBudgetMngVo.getAuditStatus()) {
			throw new UtilException("该数据已经审核无法修改！");
		}
		return toAjax(iSysBudgetMngService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 修改预算管理
	 */
	@ApiOperation("修改预算管理")
	@PreAuthorize("@ss.hasPermi('system:SysBudgetMng:edit')")
	@Log(title = "预算管理", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/audit")
	public AjaxResult<Void> audit(@Validated @RequestBody SysBudgetMngEditBo bo) {
		return toAjax(iSysBudgetMngService.auditByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除预算管理
	 */
	@ApiOperation("删除预算管理")
	@PreAuthorize("@ss.hasPermi('system:SysBudgetMng:remove')")
	@Log(title = "预算管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] ids) {
		return toAjax(iSysBudgetMngService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
